package net.oschina.app.improve.main;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import net.oschina.app.R;
import net.oschina.app.api.ApiHttpClient;
import net.oschina.app.api.remote.OSChinaApi;
import net.oschina.app.improve.main.update.CheckUpdateManager;

public class Main3Activity extends Activity {

    private ImageView imageView;
    private WebView webView;
    private Button imgBtn;
    private Button webBtn;

    NotificationManager notificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main3);

        //加载布局控件对象
        imageView = (ImageView) findViewById(R.id.img_view);
        imgBtn = (Button) findViewById(R.id.img_btn);

        webView = (WebView) findViewById(R.id.web_view);
        webBtn = (Button) findViewById(R.id.web_btn);

        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);



        imgBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Notification notification;

                Notification.Builder builder;

                //Api大于等于HONEYCOMB,使用Notification.Builder创建notification
                builder = new Notification.Builder(Main3Activity.this);
                builder.setTicker("滚动提示");  //N滚动提示
                builder.setContentTitle("应该是标题");   //标题
                builder.setContentText("这个是内容");    //内容
                builder.setSmallIcon(android.R.drawable.sym_action_chat);  //Icon 如果不设置Icon,Notification不会跳出来
                builder.setAutoCancel(false);    //点击以后是否自动清除,true-点击后自动清除,false-点击以后不会自动清除
                builder.setContentInfo("右侧提示");
                //铃声,震动,提示灯默认设置.
                // DEFAULT_ALL会忽略已经设置的震动,声音,提示等设置
                //除此还有三个参数 DEFAULT_SOUND - 默认声音, DEFAULT_VIBRATE - 默认震动, DEFAULT_LIGHTS - 默认提示灯
                builder.setDefaults(Notification.DEFAULT_ALL);
                //但设置了LargeIcon,小图标依然会在状态栏中显示.当时下拉状态的时候大图会显示在左边,小图片给显示在右下角
                builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), android.R.drawable.sym_action_call));
                //在右边显示一个数量,等价于setContentInfo函数.如果有设置setContentInfo函数,那么本函数会给覆盖
//                builder.setNumber(12);
                //是否常驻状态栏
                //builder.setOngoing(true);
                //setOnlyAlertOnce 是否提示一次.true - 如果Notification已经存在状态栏即使在调用notify函数也不会更新.
                builder.setOnlyAlertOnce(true);
                //滚动条
                //setProgress (int max, int progress, boolean indeterminate)
                //indeterminate true - 不确定的,不会显示进度,false - 根据max和progress情况显示进度条
                builder.setProgress(100, 50, false);
                //显示一个计数器
                builder.setUsesChronometer(true);

                //点击事件
                // PendingIntent ClickPending = PendingIntent.getActivity(MainActivity.this, 0, new Intent().setClass(MainActivity.this, NotificationActivity.class), 0);
                //builder.setContentIntent(ClickPending);

                //清除事件
                //PendingIntent DelPending = PendingIntent.getActivity(MainActivity.this, 0, new Intent().setClass(MainActivity.this, NotificationActivity.class), 0);
                //builder.setDeleteIntent(DelPending);

                notification = builder.build();
                notificationManager.notify(1, notification);
            }
        });
    }



}
